from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-14 14:33:14.127229
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 14, Jan, 2021
Time: 14:33:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.0885
Nobs: 171.000 HQIC: -46.0711
Log likelihood: 1902.70 FPE: 5.02016e-21
AIC: -46.7420 Det(Omega_mle): 3.01006e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.456438 0.149883 3.045 0.002
L1.Burgenland 0.137654 0.077346 1.780 0.075
L1.Kärnten -0.236371 0.062791 -3.764 0.000
L1.Niederösterreich 0.124537 0.179800 0.693 0.489
L1.Oberösterreich 0.234699 0.153548 1.529 0.126
L1.Salzburg 0.184073 0.081301 2.264 0.024
L1.Steiermark 0.079467 0.111107 0.715 0.474
L1.Tirol 0.154980 0.073661 2.104 0.035
L1.Vorarlberg 0.013029 0.070257 0.185 0.853
L1.Wien -0.133213 0.149267 -0.892 0.372
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.530482 0.191884 2.765 0.006
L1.Burgenland 0.012941 0.099020 0.131 0.896
L1.Kärnten 0.370673 0.080387 4.611 0.000
L1.Niederösterreich 0.129499 0.230185 0.563 0.574
L1.Oberösterreich -0.176214 0.196576 -0.896 0.370
L1.Salzburg 0.175674 0.104083 1.688 0.091
L1.Steiermark 0.238313 0.142242 1.675 0.094
L1.Tirol 0.144822 0.094303 1.536 0.125
L1.Vorarlberg 0.188696 0.089945 2.098 0.036
L1.Wien -0.599783 0.191095 -3.139 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301031 0.066153 4.551 0.000
L1.Burgenland 0.106390 0.034138 3.116 0.002
L1.Kärnten -0.024319 0.027714 -0.878 0.380
L1.Niederösterreich 0.061924 0.079357 0.780 0.435
L1.Oberösterreich 0.284677 0.067770 4.201 0.000
L1.Salzburg 0.000101 0.035883 0.003 0.998
L1.Steiermark -0.022091 0.049038 -0.450 0.652
L1.Tirol 0.096603 0.032511 2.971 0.003
L1.Vorarlberg 0.126266 0.031009 4.072 0.000
L1.Wien 0.075613 0.065881 1.148 0.251
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215406 0.078053 2.760 0.006
L1.Burgenland -0.008053 0.040279 -0.200 0.842
L1.Kärnten 0.023842 0.032699 0.729 0.466
L1.Niederösterreich 0.031476 0.093633 0.336 0.737
L1.Oberösterreich 0.388479 0.079961 4.858 0.000
L1.Salzburg 0.091219 0.042338 2.155 0.031
L1.Steiermark 0.182490 0.057860 3.154 0.002
L1.Tirol 0.043707 0.038360 1.139 0.255
L1.Vorarlberg 0.100606 0.036587 2.750 0.006
L1.Wien -0.070963 0.077732 -0.913 0.361
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.574999 0.155745 3.692 0.000
L1.Burgenland 0.077732 0.080371 0.967 0.333
L1.Kärnten 0.004092 0.065247 0.063 0.950
L1.Niederösterreich -0.024582 0.186832 -0.132 0.895
L1.Oberösterreich 0.134332 0.159553 0.842 0.400
L1.Salzburg 0.045960 0.084480 0.544 0.586
L1.Steiermark 0.110980 0.115452 0.961 0.336
L1.Tirol 0.224087 0.076542 2.928 0.003
L1.Vorarlberg 0.015263 0.073005 0.209 0.834
L1.Wien -0.147269 0.155105 -0.949 0.342
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167873 0.110192 1.523 0.128
L1.Burgenland -0.022618 0.056864 -0.398 0.691
L1.Kärnten -0.012286 0.046163 -0.266 0.790
L1.Niederösterreich 0.176546 0.132187 1.336 0.182
L1.Oberösterreich 0.381532 0.112886 3.380 0.001
L1.Salzburg -0.033739 0.059771 -0.564 0.572
L1.Steiermark -0.048938 0.081684 -0.599 0.549
L1.Tirol 0.195836 0.054155 3.616 0.000
L1.Vorarlberg 0.047563 0.051652 0.921 0.357
L1.Wien 0.156075 0.109739 1.422 0.155
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218537 0.139432 1.567 0.117
L1.Burgenland 0.067625 0.071953 0.940 0.347
L1.Kärnten -0.048528 0.058413 -0.831 0.406
L1.Niederösterreich -0.036068 0.167263 -0.216 0.829
L1.Oberösterreich -0.086489 0.142841 -0.605 0.545
L1.Salzburg 0.028240 0.075632 0.373 0.709
L1.Steiermark 0.371108 0.103360 3.590 0.000
L1.Tirol 0.511085 0.068525 7.458 0.000
L1.Vorarlberg 0.194809 0.065358 2.981 0.003
L1.Wien -0.218552 0.138859 -1.574 0.116
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.094409 0.163405 0.578 0.563
L1.Burgenland 0.018389 0.084324 0.218 0.827
L1.Kärnten -0.103347 0.068456 -1.510 0.131
L1.Niederösterreich 0.229737 0.196021 1.172 0.241
L1.Oberösterreich 0.021152 0.167400 0.126 0.899
L1.Salzburg 0.223444 0.088635 2.521 0.012
L1.Steiermark 0.142796 0.121130 1.179 0.238
L1.Tirol 0.095608 0.080307 1.191 0.234
L1.Vorarlberg 0.020961 0.076596 0.274 0.784
L1.Wien 0.264438 0.162733 1.625 0.104
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.598180 0.088613 6.750 0.000
L1.Burgenland -0.022942 0.045728 -0.502 0.616
L1.Kärnten -0.002176 0.037123 -0.059 0.953
L1.Niederösterreich -0.017289 0.106300 -0.163 0.871
L1.Oberösterreich 0.275581 0.090779 3.036 0.002
L1.Salzburg 0.008763 0.048066 0.182 0.855
L1.Steiermark 0.001289 0.065688 0.020 0.984
L1.Tirol 0.078778 0.043549 1.809 0.070
L1.Vorarlberg 0.168606 0.041537 4.059 0.000
L1.Wien -0.083141 0.088248 -0.942 0.346
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.150565 0.000661 0.217076 0.252049 0.066563 0.090157 -0.066760 0.157903
Kärnten 0.150565 1.000000 0.000192 0.191092 0.155109 -0.130882 0.160058 0.029838 0.303131
Niederösterreich 0.000661 0.000192 1.000000 0.280617 0.084330 0.214938 0.099230 0.063063 0.352676
Oberösterreich 0.217076 0.191092 0.280617 1.000000 0.295579 0.312133 0.078864 0.081653 0.119604
Salzburg 0.252049 0.155109 0.084330 0.295579 1.000000 0.153888 0.068029 0.077444 -0.023953
Steiermark 0.066563 -0.130882 0.214938 0.312133 0.153888 1.000000 0.098307 0.090752 -0.121567
Tirol 0.090157 0.160058 0.099230 0.078864 0.068029 0.098307 1.000000 0.150692 0.129950
Vorarlberg -0.066760 0.029838 0.063063 0.081653 0.077444 0.090752 0.150692 1.000000 0.095873
Wien 0.157903 0.303131 0.352676 0.119604 -0.023953 -0.121567 0.129950 0.095873 1.000000